-
Notifications
You must be signed in to change notification settings - Fork 339
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
impl<T> Read for UniquePtr<T> where ... Pin<&a mut T> : Read
.
#1368
Merged
dtolnay
merged 1 commit into
dtolnay:master
from
anforowicz:unique-ptr-blanker-trait-impls
Aug 15, 2024
Merged
impl<T> Read for UniquePtr<T> where ... Pin<&a mut T> : Read
.
#1368
dtolnay
merged 1 commit into
dtolnay:master
from
anforowicz:unique-ptr-blanker-trait-impls
Aug 15, 2024
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Can you PTAL? Some notes:
|
This commit implements forwarding of `Read` trait implementation from `UniquePtr<T>` to the pointee type. This is quite similar to how `Box<T>` also forwards - see https://doc.rust-lang.org/std/boxed/struct.Box.html#impl-Read-for-Box%3CR%3E Just as with `Box<T>`, the `impl` cannot be provided in the crate introducing `T`, because this violates the orphan rule. This means that before this commit a wrapper newtype would be required to work around the orphan rule - e.g.: ``` struct UniquePtrOfReadTrait(cxx::UniquePtr<ffi::ReadTrait>); impl Read for UniquePtrOfReadTrait { … } ``` After this commit, one can provide an `impl` that works more directly with the C++ type `T` (the FFI will typically require passing `self: Pin<&mut ffi::ReadTrait>`): ``` impl<'a> Read for Pin<&'a mut ffi::ReadTrait> { … } ``` For a more specific motivating example, please see: https://docs.google.com/document/d/1EPn1Ss-hfOC6Ki_B5CC6GA_UFnY3TmoDLCP2HjP7bms
anforowicz
force-pushed
the
unique-ptr-blanker-trait-impls
branch
from
August 14, 2024 19:22
338d987
to
c23c7ad
Compare
dtolnay
approved these changes
Aug 15, 2024
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
I am open to separate PRs for forwarding other traits (Write
, PartialEq
) as someone comes across a real use case for those.
hubot
pushed a commit
to google/skia
that referenced
this pull request
Aug 15, 2024
After dtolnay/cxx#1368 we can simplify the FFI code a little bit, because now there is no need for a separate newtype wrapper for `cxx::UniquePtr<ffi::ReadTrait>`. Bug: chromium:359917956 Change-Id: Ib30413f45e0b41c54f87b35c78f6a65fda2015b3 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/889876 Reviewed-by: Brian Osman <[email protected]> Commit-Queue: Łukasz Anforowicz <[email protected]>
anforowicz
added a commit
to anforowicz/cxx
that referenced
this pull request
Nov 22, 2024
This commit implements forwarding of `Write` trait implementation from `UniquePtr<T>` to the pointee type. This is quite similar to how `Box<T>` also forwards - see https://doc.rust-lang.org/std/boxed/struct.Box.html#impl-Write-for-Box%3CW%3E This commit has quite similar, orphan-rule-related motivation as the earlier dtolnay#1368 which covered the `Read` trait. For a more specific motivating example, please see http://review.skia.org/c/skia/+/923337/3/experimental/rust_png/ffi/FFI.rs#254
anforowicz
added a commit
to anforowicz/cxx
that referenced
this pull request
Nov 22, 2024
This commit implements forwarding of `Write` trait implementation from `UniquePtr<T>` to the pointee type. This is quite similar to how `Box<T>` also forwards - see https://doc.rust-lang.org/std/boxed/struct.Box.html#impl-Write-for-Box%3CW%3E This commit has quite similar, orphan-rule-related motivation as the earlier dtolnay#1368 which covered the `Read` trait. For a more specific motivating example, please see http://review.skia.org/skia/+/923337/3/experimental/rust_png/ffi/FFI.rs#254
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This commit implements forwarding of
Read
trait implementation fromUniquePtr<T>
to the pointee type. This is quite similar to howBox<T>
also forwards - seehttps://doc.rust-lang.org/std/boxed/struct.Box.html#impl-Read-for-Box%3CR%3E
Just as with
Box<T>
, theimpl
cannot be provided in the crate introducingT
, because this violates the orphan rule. This means that before this commit a wrapper newtype would be required to work around the orphan rule - e.g.:After this commit, one can provide an
impl
that works more directly with the C++ typeT
(the FFI will typically require passingself: Pin<&mut ffi::ReadTrait>
):For a more specific motivating example, please see: https://docs.google.com/document/d/1EPn1Ss-hfOC6Ki_B5CC6GA_UFnY3TmoDLCP2HjP7bms